package com.example.swing.jframe2;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class JFrameButton extends JFrame {
    private JButton
            button1 = new JButton("Button1"),
            button2 = new JButton("Button2");
    private JTextField txt = new JTextField(10);

    class ButtonListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            String name = ((JButton) e.getSource()).getText();
            txt.setText(name);
        }
    }

    private ButtonListener bl = new ButtonListener();

    public JFrameButton() {
        button1.addActionListener(bl);
        button2.addActionListener(bl);
        setLayout(new FlowLayout());
        add(button1);
        add(button2);
        add(txt);
    }

    public static void main(String[] args) {
        //run(new JFrameButton(), 200, 150);
    }
}
